{include file="public/header" /}
<style type="text/css">.gray-bg {
    background: #fff;
}

.wrapper {
    padding: 0px;
}

.layui-form-checkbox i {
    height: 30px !important;
}</style>
<body class="gray-bg" id="body">
<div class="wrapper wrapper-content">
    <div class="row">
        <form class="form-horizontal" method="post">
            <div class="col-sm-12">
                <div class="ibox-content">


                    <div class="form-group ">
                        <label class="col-sm-2 control-label">用户id：</label>
                        <div class="col-sm-4">
                            <input type="text" name="begin_id" class="layui-input" id="begin_id" value=""
                                   onKeyUp="this.value=this.value.replace(/[^\.\d]/g,'');this.value=this.value.replace('.','');"
                                   placeholder="开启用户id">
                        </div>
                        <div class="col-sm-4">
                            <input type="text" name="end_id" class="layui-input" id="end_id" value=""
                                   onKeyUp="this.value=this.value.replace(/[^\.\d]/g,'');this.value=this.value.replace('.','');"
                                   placeholder="结束用户id">
                        </div>
                        <div class="col-sm-1">
                            &nbsp;
                        </div>
                    </div>
                    <div class="form-group ">
                        <label class="col-sm-2 control-label"></label>
                        <div class="layui-progress layui-progress-big col-sm-9" lay-showpercent="true"
                             lay-filter="demo">
                            <div class="layui-progress-bar layui-bg-red" lay-percent="0%"></div>
                        </div>
                        <div class="col-sm-1">
                            &nbsp;
                        </div>
                    </div>
                    <div class="form-group  ">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-9">
                            <p class="layui-btn site-demo-active" data-type="loading">模拟loading</p>
                            <!--<a  class="btn btn-w-m btn-primary" style="display: block; width: 120px;margin-left: 0;" ><i class="fa fa-check"></i> &nbsp;g</a>-->
                        </div>
                    </div>

                </div>
            </div>
            <input type="hidden" name="id" value="{$name.id|default=0}"/>
            <input name="longitude" id="longitude" type="hidden" class="form-control"
                   value="{$name.longitude|default=''}"/>
            <input name="latitude" id="latitude" type="hidden" class="form-control"
                   value="{$name.latitude|default=''}"/>
        </form>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript" src="__STYLE__/admin/js/area.js?ver=20200522"></script>
{load href="__STYLE__/admin/plugins/iCheck/icheck.min.js"}
{load href="__STYLE__/admin/plugins/iCheck/custom.css"}
<script>

    layui.use('element', function () {
        var $ = layui.jquery
            , element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
        $('.site-demo-active').on('click', function () {
            var begin_id = parseInt($("#begin_id").val());
            var end_id = parseInt($("#end_id").val());
            if (begin_id > end_id) {
                layer.msg("开启id不能大于结束id", {icon: 5, time: 2000});
                return;
            }
            var othis = $(this);
            var DISABLED = 'layui-btn-disabled';
            if (othis.hasClass(DISABLED)) return;
            //模拟loading
            var total = end_id - begin_id + 1;
            var diff = 100 / total;

            var i = 0, timer = setInterval(function () {
                i += diff;
                if (i > 100) {
                    element.progress('demo', '100%');
                    othis.addClass(DISABLED);
                    clearInterval(timer);
                    othis.removeClass(DISABLED);
                    return;
                }
                if (begin_id <= end_id) {
                    $.post("{:url('Member/updateToken')}", {id: begin_id},
                        function (data) {
                            begin_id++;
                            element.progress('demo', getFloat(i, 1) + '%');
                            othis.addClass(DISABLED);
                        });
                }

            }, Math.ceil(Math.random() * 1000) + 1300);
        });
    });


    function getFloat(num, n) {
        n = n ? parseInt(n) : 0;
        if (n <= 0) {
            return Math.round(num);
        }
        num = Math.round(num * Math.pow(10, n)) / Math.pow(10, n); //四舍五入
        num = Number(num).toFixed(n); //补足位数
        return num;
    };
</script>
